package chixing.day12.work.w1;

import java.util.ArrayList;
import java.util.List;

public class MailAddressArrayList {
    private List<MailAddress> addressObj;

    public MailAddressArrayList() {
        addressObj = new ArrayList<>();
    }

    public void add(MailAddress address) {
        addressObj.add(address);
    }

    public void display() {
        System.out.println("所有客户邮件地址:\n");
        for (MailAddress address : addressObj) {
            System.out.println(address);
        }
    }

    public void getByLastName(String name) {
        System.out.println("\n查询姓名包含 '" + name + "' 的客户:\n");
        boolean found = false;

        for (MailAddress address : addressObj) {
            if (address.getName().contains(name)) {
                System.out.println(address);
                found = true;
            }
        }

        if (!found) {
            System.out.println("未找到姓名包含 '" + name + "' 的客户");
        }
    }
}

